package ${cfg.rootPath}.controller;

import ${cfg.rootPath}.data.${entity}Data;
import ${cfg.rootPath}.service.${entity}Service;
import com.chaos.framework.model.dto.ID;
import com.chaos.framework.model.dto.page.PageQueryDto;
import com.chaos.framework.model.dto.result.data.BooleanResult;
import com.chaos.framework.model.dto.result.data.DataResult;
import com.chaos.framework.model.dto.result.list.ListResult;
import com.chaos.framework.model.dto.result.page.PageResult;
import com.chaos.framework.starter.base.BaseController;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
*
* @author ${author}
* @since ${date}
*/
@RestController
@AllArgsConstructor
@RequestMapping(value = {"/${table.entityPath}"})
@Tag(name = "${table.comment}", description = "${table.comment}")
public class ${table.controllerName} extends BaseController<${entity}Data> {

    private final ${entity}Service ${table.entityPath}Service;

    @PostMapping("/one.admin")
    @ApiOperation(value = "<#if table.comment??>${table.comment}<#else>${entity}</#if>详情", httpMethod = "POST")
    public DataResult<${entity}Data> one(@RequestBody ID data){
        return dataResult(${table.entityPath}Service.selectByID(data));
    }

    @PostMapping("/list.admin")
    @ApiOperation(value = "<#if table.comment??>${table.comment}<#else>${entity}</#if>列表", httpMethod = "POST")
    public ListResult<${entity}Data> list(@RequestBody ${entity}Data data){
        return listResult(${table.entityPath}Service.selectByData(data));
    }

    @PostMapping("/page.admin")
    @ApiOperation(value = "<#if table.comment??>${table.comment}<#else>${entity}</#if>分页", httpMethod = "POST")
    public PageResult<${entity}Data> page(@RequestBody PageQueryDto<${entity}Data> data){
        return pageResult(${table.entityPath}Service.selectByPage(data));
    }

    @PostMapping("/add.admin")
    @ApiOperation(value = "新增<#if table.comment??>${table.comment}<#else>${entity}</#if>", httpMethod = "POST")
    public DataResult<ID> add(@RequestBody ${entity}Data data){
        return dataResult(${table.entityPath}Service.insertModel(data));
    }

    @PostMapping("/update.admin")
    @ApiOperation(value = "编辑<#if table.comment??>${table.comment}<#else>${entity}</#if>", httpMethod = "POST")
    public BooleanResult update(@RequestBody ${entity}Data data){
        return booleanResult(${table.entityPath}Service.updateModelByID(data));
    }

    @PostMapping("/delete.admin")
    @ApiOperation(value = "删除<#if table.comment??>${table.comment}<#else>${entity}</#if>", httpMethod = "POST")
    public BooleanResult delete(@RequestBody ID data){
        return booleanResult(${table.entityPath}Service.deleteModel(data));
    }

}
